/**
 * 防抖装饰器
 * 用于防止快速点击时重复触发方法
 * @param delay 延迟时间，默认300ms
 */
export function debounce(delay: number = 300) {
  return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
    const originalMethod = descriptor.value;
    let timeoutId: any;

    descriptor.value = function (...args: any[]) {
      clearTimeout(timeoutId);
      timeoutId = setTimeout(() => {
        originalMethod.apply(this, args);
      }, delay);
    };

    return descriptor;
  };
}

/**
 * 防抖函数
 * 用于包装任何函数，使其具有防抖功能
 * @param func 要防抖的函数
 * @param delay 延迟时间，默认300ms
 */
export function debounceFunction<T extends (...args: any[]) => any>(
  func: T,
  delay: number = 300
): (...args: Parameters<T>) => void {
  let timeoutId: any;
  
  return function (...args: Parameters<T>) {
    clearTimeout(timeoutId);
    timeoutId = setTimeout(() => {
      func.apply(this, args);
    }, delay);
  };
} 